package com.sh1604.duitang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sh1604.duitang.R;
import com.sh1604.duitang.mybean.ImageBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * ***********************************************************
 * author: jie
 * time: 2016/7/20 19:46
 * name:
 * overview:Build.VERSION.SDK_INT:版本号
 * usage:
 * *************************************************************
 */
public class GvAdapter extends BaseAdapter {
    private List<ImageBean.DataBean.GroupItemsBean> mDatas;
    private Context mContext;

    public GvAdapter(Context context, List<ImageBean.DataBean.GroupItemsBean> datas) {
        this.mContext = context;
        this.mDatas = datas;
    }

    @Override
    public int getCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        GvHolder gHolder = null;
        if (convertView==null){
            gHolder = new GvHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gv,parent,false);
            gHolder.item_iv1 = (ImageView) convertView.findViewById(R.id.item_iv1);
            gHolder.item_tv1 = (TextView) convertView.findViewById(R.id.find_tv1);
            convertView.setTag(gHolder);
        }else {
            gHolder = (GvHolder) convertView.getTag();
        }
        if (this.mDatas!=null){
            ImageBean.DataBean.GroupItemsBean bean = mDatas.get(position);
            if (gHolder!=null){
                Picasso.with(mContext).load(bean.getIcon_url()).into(gHolder.item_iv1);
                gHolder.item_tv1.setText(bean.getName());
            }
        }
        return convertView;
    }

    private class GvHolder {
        private ImageView item_iv1;
        private TextView item_tv1;
    }
}
